<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'sj';
if($_RQ['op']=='sj'){
	$return=array();
	if($_RQ['plugin_name']){
		$this->session('typename',$_RQ['plugin_name']);
	}
	$typename=$this->session('typename');
	if(!$typename){
		 exi('访问异常，不能获取海报！','','sj');
	}
	$item=plugin($typename)->plugin_setting('poster');
	$data=plugin($typename)->apidatademo?:$this->apidatademo;
	$item['data']['data']=$item['data']['data']?:$data;
	$bgimage='/addons/'.$typename.'/resource/images/bg.jpg';
	if(!file_exists(ROOT_D.$bgimage)){
		$bgimage='../addons/jy_poster/resource/images/bg.jpg';
	}else{
		$bgimage='..'.$bgimage;
	}
	$item['data']['image']=$item['data']['image']?:$bgimage;
	$item['image']=$item['data']['image'];
	$item['url']=custom_url('jy_poster/apibuild//plugin_name='.$typename,true);
	$return['item']=$item;
	$return['datademo']=array('data'=>$data);
	$return['datatypes']=$this->datatypes;
	$return['datapushs']=$this->datapushs;
	exi($return);
}
if($_RQ['op']=='qc'){
	$typename=$this->session('typename');
	$path=ROOT_AT .'/oss/'.$_SESSION['uniacid'].'/images/jy_poster/api/';
	$handle = scandir($path);
	foreach($handle as $val){
    	//排除目录中的.和..
    	if($val !="." && $val !=".."){
    		//如果是文件直接删除
    		unlink($path.$val);
		}
   }
   $like='oss/'.$_SESSION['uniacid'].'/images/jy_poster/api/';
   pdo_delete('core_attachment',array('attachment like'=>'%'.trim($like).'%','uniacid'=>$_SESSION['uniacid']));
   exi('清除成功');
}

if($_RQ['op']=='design'){
	$postdata=get_postdata();
	$typename=$this->session('typename');
	plugin($typename)->plugin_setting('poster',$postdata);
	exi('设置成功');
}
